package cn.amossun.starter.event.handler;

import cn.amossun.starter.event.annoation.EventListener;
import cn.amossun.starter.event.annoation.*;
import cn.amossun.starter.event.property.*;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.AnnotationUtils;

import java.lang.reflect.Method;

@Data
@Slf4j
public class EventQueueContextProcessor implements QueueContextHolder {

    private EventContext eventContext;

    public EventQueueContextProcessor(EventContext eventContext) {
        this.eventContext = eventContext;
    }

    @Override
    public void processListener(Object bean, String beanName, Method method) {
        EventListener eventListener = AnnotationUtils.findAnnotation(method, EventListener.class);
        if (eventListener != null) {

            String defaultQueueName = getQueueName(bean, beanName, method);
            eventContext.addQueues(buildEventQueueContexts(eventListener, defaultQueueName));
        }
    }

    @Override
    public void processPublisher(Object bean, String beanName, Method method) {
        EventPublisher eventPublisher = AnnotationUtils.findAnnotation(method, EventPublisher.class);
        if (eventPublisher != null) {
            eventContext.addQueue(buildEventQueueContexts(eventPublisher));
        }
    }

    @Override
    public void processMulticaster(Object bean, String beanName, Method method) {
        EventMulticaster eventMulticaster = AnnotationUtils.findAnnotation(method, EventMulticaster.class);
        if (eventMulticaster != null) {

        }
    }

}
